package org.frv.wispr.business;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.*;

@Entity
@Table(name="ACCOUNT_ENTRIES")	
public class AccountEntry {
	private long id;
	private String description;
	private Integer index;
	private BigDecimal debit;
	private BigDecimal credit;
	private Date date;
    private BigDecimal balance;
    private Account account;


    public AccountEntry() {}

    public AccountEntry(Integer index, BigDecimal debit, BigDecimal credit, String description, Date date) {
        this.index = index;
        this.debit = debit;
        this.credit = credit;
        this.description = description;
        this.date = date;
    }
    
    @ManyToOne(optional = false)
    @JoinColumn(name="account_id")
    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }

    @Transient
    public BigDecimal getBalance() {
    return balance;
}

    public void setBalance(BigDecimal balance) {
        this.balance = balance;
    }
	
	@Id @GeneratedValue(strategy=GenerationType.AUTO)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	@Column(name="entry_index", nullable=false)
	public Integer getIndex() {
		return index;
	}

	public void setIndex(Integer index) {
		this.index = index;
	}

	public BigDecimal getDebit() {
		return debit;
	}

	public void setDebit(BigDecimal debit) {
		this.debit = debit;
	}

	public BigDecimal getCredit() {
		return credit;
	}

	public void setCredit(BigDecimal credit) {
		this.credit = credit;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="entry_date", nullable=false)
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}


    private AccountEntry doubleEntry;

    @OneToOne
    public AccountEntry getDoubleEntry() {
        return doubleEntry;
    }

    public void setDoubleEntry(AccountEntry doubleEntry) {
        this.doubleEntry = doubleEntry;
    }

//    private AccountEntry reverseEntry;
//
//    @OneToOne(mappedBy = "doubleEntry", optional = false)
//    public AccountEntry getReverseEntry() {
//        return reverseEntry;
//    }
//
//    public void setReverseEntry(AccountEntry reverseEntry) {
//        this.reverseEntry = reverseEntry;
//    }
}
